package org.apache.iotdb.admin.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger配置类
 */
@Configuration
@EnableSwagger2
@Profile({"dev", "test"})
public class swagger2Config {

    @Value("${swagger.enabled}")
    private boolean enableSwaager;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiinfo())
                .enable(enableSwaager)
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.apache.iotdb.admin.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiinfo() {
        return new ApiInfoBuilder()
                .title("IOTDB接口文档")
                .description("iotDB层级关系 存储组 -> 实体(设备) -> 测点(时间序列)")
                .build();
    }


}
